home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
basic
/
glib19.zip
/
MFEDDEMO.BAS
< prev
next >
Wrap
BASIC Source File
|
1991-06-27
|
21KB
|
683 lines
' FED - DEMO
' Version III - demonstrates the use of a LEVEL parameter
' to handle an entire record I/O in a loop and
' one or 2 MFed CALLS - NO GOTOs!!!!!
'
' Note that Macros are not actually used, just the
' editting features of it.
'
' Text input demo
' Demonstrates the use of MFed and several other GLib routines
'
' Author: Gizmo Mike
' (C) InfoSoft, 1987, 1988, 1989
'
' define named common block for most FED variables
'
DECLARE FUNCTION MFed% (ed$, fsiz%, Macro$())
DECLARE FUNCTION ArgCnt%
DECLARE FUNCTION ArgVar$ (which%)
DECLARE FUNCTION NFrmat% (nst$, m%, p%)
DECLARE FUNCTION DlrFrmat% (nst$, m%, p%)
COMMON SHARED /MFedVars/ fg%, bg%, fgd%, bgd%, Alarm%, bad$, editted%, hatch%, nums%, num$, upcase%, Mac%, RngLo#, RngHi#
DECLARE SUB SaveScrn (SEG arry%)
DECLARE SUB RestScrn (SEG arry%)
CLEAR
DEFINT A-Z
OPTION BASE 1
hatch = 176 ' define hatching character
Mac = 0 ' signal macros not used
TYPE structure ' set up employee structure
NName AS STRING * 25
Phone AS STRING * 8
Addr AS STRING * 25
City AS STRING * 10
State AS STRING * 2
Zip AS STRING * 5
Dept AS STRING * 6
Superv AS STRING * 12
PFreq AS STRING * 1
PRate AS SINGLE
PIN AS INTEGER
END TYPE
DIM Emp AS structure ' DIM emp as TYPE struct
REDIM a$(11) ' temp holding for emp structures
'make sure it is set up right
CLS : SOUND 750, 2: LOCATE 5, 5
PRINT "Depending on your display, you may want to restart this demo"
LOCATE 7, 5
PRINT "with the command line parameter [/CMD /NC] or [/CMD /C]. /NC for"
LOCATE 9, 5
PRINT "No Color, /C for color version."
LOCATE 13, 5
PRINT "Tap `S' to stop the demo, any other key to continue."
GOSUB WaitKey
IF ky$ = "S" OR ky$ = "s" THEN
SYSTEM
END IF
'*********** get command line parms and set colors
q% = ArgCnt
CMode = 1 ' assume color
FOR x = 1 TO q
IF UCASE$(ArgVar$(x)) = "/NC" THEN
CMode = 0 ' user wants no color
EXIT FOR
END IF
NEXT x
IF CMode THEN ' find out if command line wants color
fg = 2: bg = 0 ' general colors
fge = 12: bge = 3 ' err message colors
fgw = 14: bgw = 4 ' window colors
fgd = 10: bgd = 0 ' data colors
fgh = 15: bgh = 1 ' help colors
fgb = 4: bgb = 0 ' box color
fgt = 3: bgt = 0 ' text colors
ELSE
fg = 7: bg = 0
fge = 15: bge = 0
fgw = 0: bgw = 7
fgd = 15: bgd = 0
fgh = 7: bgh = 15
fgb = 15: bgb = 0
fgt = 7: bgt = 0
END IF
eattr = (bge * 16) + fge ' error message attributes
wattr = (bgw * 16) + fgw ' window attributes
hattr = (bgh * 16) + fgh ' help window attributes
CALL WShadow(1)
Adding = 0
REM $DYNAMIC
REDIM Sarry(4000) ' dimension screen array for 2 screens
DIM hlp$(10) ' String array to hold help screen msgs for use later.
' Has to be DIMmed in code prior to other references
' to hlp$().
hlp$(1) = "Home - Start of line End - End of line"
hlp$(2) = " "
hlp$(3) = "Ctrl-X Clear Field Ctrl-End Clear to end of line"
hlp$(4) = "Ctrl-U Undo <Arrows> Fwd, Bkwd 1 field "
hlp$(5) = " "
hlp$(6) = " PgUp / Ctrl PgUp - Jump to first field "
hlp$(7) = " PgDn / Ctrl PgDn - Jump to last field "
hlp$(8) = " "
hlp$(9) = "[Esc] or [F9] Aborts Current Edit [F10] Save Record"
hlp$(10) = "[ Tap any key to continue ]"
prg.start: '*************** start of program *****************
GOSUB GenDisp ' put screen mask on screen
CALL SaveScrn(Sarry(1)) ' save it - RSTSCRN is quicker next time
GOSUB OpenFil ' open the file
IF hi = 0 THEN ' in case you lost the EMP.DAT file
GOSUB newfil
END IF
recno = hi ' get the top rec no
GOSUB RecDisp ' display given record
'----------------------------------------------------------------------------
' This is one big loop with several SELECT CASE constructs in it.
'
' One CASE construct sets the level or a pointer to the field that we
' are currently editing.
'
' Based on that level, another CASE construct sets the FED parameters
' for the next call. ie if we are on level 2 (phone), then we need to
' set nums ON.
'
' One other CASE block intercepts those fields that need further data
' verification and perfomrs that check.
'
' The data is read from file into the TYPE structure and then stored
' in a string array for the level pointer indexing, then stored BACK
' to the TYPE structure for saving to disk. You should not perform
' I/O directly on TYPE elements.
' The random access file code contained here is pretty minimal - just
' enough to be able to demo FED. In a "real" random file application,
' there are a number of things that should be done in the way of checking
' for valid data, also, there are functions missing like to delete a
' record (missing because it does not lend itself to demoing FED or GLIB
' - this is not a QB tutor!).
' There ARE several other GLIB functions used:
' ERRMSG, DLRFRMAT, NFRMAT, WDW and a few others.
'---------------------------------------------------------------------------
level = 1 ' indicates active FIELD in record
fsiz = 25 ' first field siz
rx = 4 ' input location
ry = 10
Alarm = 1 ' beeper on
done = 0
REDIM Macro$(1)
DO
LOCATE rx, ry ' locate current location
PRINT a$(level) ' print string
LOCATE rx, ry ' reset to SOS
FCode = MFed(a$(level), fsiz, Macro$())
' first, we want to intercept the 2 numeric inputs and
' check them. All validity checking would go here.
SELECT CASE level
CASE 2 ' check the phone
temp$ = a$(2)
DO
m = 1: p = 0 ' m sets NFRMAT mode, p is useless here
errc = NFrmat(temp$, m, p)
IF m <> 1 THEN ' something went wrong !!
' tell them of error
CALL ERRMSG(temp$, 24, eattr%, 2)
temp$ = a$(2)
LOCATE rx, ry
FCode = MFed(a$(level), fsiz, Macro$())
END IF
LOOP UNTIL m = 1
a$(2) = temp$
CASE 9
IF INSTR("HS", a$(9)) = 0 THEN
CALL ERRMSG("Pay Frequency code must be H or S only.", 24, eattr%, 2)
ret$ = " "
CALL GetCH("HS", ret$) ' mask the input
a$(9) = ret$
END IF
CASE 10
temp$ = a$(10)
DO
m = 0: p = 2 ' set up for dollar formatting call
errc = DlrFrmat(temp$, m%, p%)
IF m <> 0 THEN ' if m is changed
CALL ERRMSG(temp$, 24, eattr, 2)
temp$ = a$(10)
LOCATE rx, ry
FCode = MFed(temp$, fsiz, Macro$())
END IF
LOOP UNTIL m = 0
CASE ELSE
END SELECT
SELECT CASE FCode ' handle the exit return first
CASE 0, 2 ' down = enter for this
level = level + 1
' "wrap" from last to first field
IF level > UBOUND(a$) THEN level = 1
CASE 1 ' UP
IF level - 1 > 0 THEN
level = level - 1
END IF
CASE 11 ' F1 key pressed (HELP)
CALL SaveScrn(Sarry(2001)) ' save screen as is
CALL wdw(7, 12, 17, 72, 1, 1, 2, hattr, "Editting Help")
FOR x = 1 TO 9 ' pop help window up
CALL QPrint(hlp$(x), 7 + x, 14, hattr%)
NEXT x ' QUIKPRT help